impl Solution {
    pub fn min_operations( mut nums: Vec<i32>, x: i32) -> i32 {
        let all_sum:i32=nums.iter().sum();
        if all_sum.lt(&x){
            return  -1;
        }
        let mut ans=1<<31-1;
        let mut sum=0;
        let pre_sum :Vec<_>=nums.iter().enumerate().map(|(ind,value)|{
            sum+=value;
            if sum==x{
                ans=ans.min(ind+1)
            }
            sum
        }).collect();
        let mut sum=0;
        nums.reverse();
        let mut end_sum :Vec<_>=nums.iter().enumerate().map(|(ind,value)|{
            sum+=value;
            if sum==x{
                ans=ans.min(ind+1)
            }
            sum
        }).collect();
        end_sum.reverse();
        println!("{:?}",end_sum);
        let mut ib =0;
        for (ind,a) in pre_sum.iter().enumerate(){
            if *a>=x{
                break;
            }
            println!("{}",a);
            while ib<end_sum.len(){
                let b=end_sum[ib];
                match (a+b).cmp(&x){
                    std::cmp::Ordering::Equal => {
                        ans=ans.min(ind+end_sum.len()-ib+1);
                        ib+=1;
                    },
                    std::cmp::Ordering::Greater=>ib+=1,
                    std::cmp::Ordering::Less=>break,
                }
                
            }
        }
        if ans==1<<31-1{
            -1
        }else{
            ans as i32
        }

        
    }
}
